//
//  GYShopCell.m
//  GoodLuck
//
//  Created by apple on 2018/1/31.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYShopCell.h"
#import "UIImageView+GYExtension.h"
#import "UILabel+GYExtension.h"

@interface GYShopCell ()

/** 商品图片 */
@property (nonatomic, strong) UIImageView *coverimageView;

/** 商品描述 */
@property (nonatomic, strong) UILabel *descrptionLable;

/** 商品价格 */
@property (nonatomic, strong) UILabel *pirceLable;


@end


@implementation GYShopCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 4;
        self.layer.masksToBounds = YES;
        //初始化
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    //1.添加子控件
    UIImageView *shopImageView = [UIImageView layoutImageView:@"3"];
    [self.contentView addSubview:shopImageView];
    self.coverimageView = shopImageView;
    
    UILabel *lable = [UILabel layoutWith:@"sdad" line:2 textColor:[UIColor blackColor]];
    lable.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:lable];
    self.descrptionLable = lable;
    
    UILabel *pirceLable = [UILabel layoutWith:@"¥121.00" line:1 textColor:RGBColor(255, 137, 1)];
    pirceLable.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:pirceLable];
    self.pirceLable = pirceLable;
    
    UILabel *bgLable = [UILabel layoutLbale:RGBColor(240, 240, 240)];
    [self.contentView addSubview:bgLable];
    
    //2.布局子控件
    NSDictionary *dic = @{@"shopImageView":shopImageView,@"lable":lable,@"pirceLable":pirceLable,@"bgLable":bgLable};
    NSDictionary *metric = @{@"shopHeight":@((ScreenWidth-30)/2)};
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[shopImageView]-0-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[shopImageView(shopHeight)]" options:0 metrics:metric views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-2-[lable]-0-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[shopImageView]-10-[lable(50)]" options:0 metrics:nil views:dic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-2-[bgLable]-2-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[lable]-5-[bgLable(1)]" options:0 metrics:nil views:dic]];

    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-2-[pirceLable]-0-|" options:0 metrics:nil views:dic]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[lable]-10-[pirceLable]" options:0 metrics:nil views:dic]];
}


- (void)setGoods:(GYGoods *)goods {
    _goods = goods;
    
    [self.coverimageView sd_setImageWithURL:[NSURL URLWithString:goods.goods_image] placeholderImage:[UIImage imageNamed:@"4"]];
    self.descrptionLable.text = goods.goods_name;
    self.pirceLable.text = [NSString stringWithFormat:@"¥%@",goods.goods_promotion_price];
}





@end
